package com.intpro.demo.Service;

import com.intpro.demo.DAO.Message;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service
public class MessageSevice
{

	@Autowired
	MongoTemplate mongoTemplate;

	public void addMsg(Message m)
	{
		mongoTemplate.insert(m);
	}

	public void readMsg(long id)
	{
		Query q1 = new Query(Criteria.where("id").is(id));
		Message m = mongoTemplate.findOne(q1, Message.class);

		m.hsread = true;

		mongoTemplate.save(m);
	}

	public List<Message> findMsgByToid(long toid)
	{
		Query q1 = new Query(Criteria.where("toid").is(toid));
		List<Message> m = mongoTemplate.find(q1, Message.class);
		return m;
	}
	
}
